package com.example.tired1.recycleview_article_14120200131_shiyining.activity;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.tired1.recycleview_article_14120200131_shiyining.R;
import com.example.tired1.recycleview_article_14120200131_shiyining.adapter.Articleadapter;
import com.example.tired1.recycleview_article_14120200131_shiyining.bean.ArticleBean;
import com.example.tired1.recycleview_article_14120200131_shiyining.iface.ArticleListener;
import com.example.tired1.recycleview_article_14120200131_shiyining.model.ArticleModel;

import java.util.List;

public class MainActivity extends AppCompatActivity implements ArticleListener{
   RecyclerView recyclerView;
    Context context;
    List<ArticleBean>list;
    Articleadapter articleadapter;
    RecyclerView.LayoutManager layoutManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context=MainActivity.this;

        recyclerView=(RecyclerView)findViewById(R.id.recycleView);
        articleadapter=new Articleadapter(context,list);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(articleadapter);

        ArticleModel articleModel=new ArticleModel();
        articleModel.getResultList("article",2,"rv1l2tidbomann2qn86nln6ur2",this);

    }

    @Override
    public void onResponse(List<ArticleBean> beanList) {//网络访问成功的处理
        list=beanList;
        articleadapter.setList(list);//把最新的list数据传递到adpter里，更新显示



    }

    @Override
    public void onFail(String msg) {//网络访问失败的处理
        Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();

    }
}
